package api

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/wending/h5/config"
	"net/http"
	"net/url"
)

type RechargeListApiService service

type RechargeListRequest struct {
	ctx        context.Context
	ApiService *RechargeListApiService
	siteId     *uint
	startTime  *uint64
	endTime    *uint64
	page       *uint64
	pageSize   *uint64
	payStatus  *uint
}

type RechargeListResponse struct {
	Code    *int64            `json:"code,omitempty"`
	Message *string           `json:"message,omitempty"`
	Data    *RechargeListData `json:"data,omitempty"`
}

type RechargeListData struct {
	TotalPage    *uint64             `json:"totalPage,omitempty"`
	RechargeList []*RechargeListItem `json:"rechargeList,omitempty"`
}

type RechargeListItem struct {
	UserId           *uint64 `json:"userId,omitempty"`
	NickName         *string `json:"nickName,omitempty"`
	Ip               *string `json:"ip,omitempty"`
	UserAgent        *string `json:"userAgent,omitempty"`
	UserFollowTime   *uint64 `json:"userFollowTime,omitempty"`
	UserRegisterTime *uint64 `json:"userRegisterTime,omitempty"`
	WxOriginalId     *string `json:"wx_originalId,omitempty"`
	WxMpName         *string `json:"wx_mpName,omitempty"`
	WxUserOpenId     *string `json:"wx_user_openId,omitempty"`
	RechargeUuid     *string `json:"rechargeUuid,omitempty"`
	EwTradeId        *string `json:"ewTradeId,omitempty"`
	PayTime          *uint64 `json:"payTime,omitempty"`
	RechargeMethod   *uint   `json:"rechargeMethod,omitempty"`
	Money            *uint   `json:"money,omitempty"`
	CreateTime       *uint64 `json:"createTime,omitempty"`
	UpdateTime       *uint64 `json:"updateTime,omitempty"`
	PayStatus        *uint   `json:"payStatus,omitempty"`
	SourceUuid       *string `json:"sourceUuid,omitempty"`
	BookTitle        *string `json:"bookTitle,omitempty"`
	LinkId           *uint64 `json:"linkId,omitempty"`
	LinkName         *string `json:"linkName,omitempty"`
	ExternalUserId   *string `json:"externalUserId,omitempty"`
	ThirdCorpId      *string `json:"thirdCorpId,omitempty"`
}

func (r *RechargeListRequest) Execute() (*RechargeListResponse, *http.Response, error) {
	return r.ApiService.getExecute(r)
}

func (r *RechargeListRequest) ConsumerKey(ConsumerKey string) *RechargeListRequest {
	r.ctx = context.WithValue(r.ctx, config.ConsumerKey, ConsumerKey)
	return r
}

func (r *RechargeListRequest) SecretKey(SecretKey string) *RechargeListRequest {
	r.ctx = context.WithValue(r.ctx, config.SecretKey, SecretKey)
	return r
}

func (r *RechargeListRequest) SiteId(siteId uint) *RechargeListRequest {
	r.siteId = &siteId
	return r
}

func (r *RechargeListRequest) StartTime(startTime uint64) *RechargeListRequest {
	r.startTime = &startTime
	return r
}

func (r *RechargeListRequest) EndTime(endTime uint64) *RechargeListRequest {
	r.endTime = &endTime
	return r
}

func (r *RechargeListRequest) Page(page uint64) *RechargeListRequest {
	r.page = &page
	return r
}

func (r *RechargeListRequest) PageSize(pageSize uint64) *RechargeListRequest {
	r.pageSize = &pageSize
	return r
}

func (r *RechargeListRequest) PayStatus(payStatus uint) *RechargeListRequest {
	r.payStatus = &payStatus
	return r
}

func (r *RechargeListRequest) WithLog(enable bool) *RechargeListRequest {
	if enable {
		r.ctx = context.WithValue(r.ctx, config.ContextEnableLog, true)
	}
	return r
}

func (a *RechargeListApiService) Get(ctx context.Context) *RechargeListRequest {
	return &RechargeListRequest{
		ApiService: a,
		ctx:        ctx,
	}
}

func (a *RechargeListApiService) getExecute(r *RechargeListRequest) (*RechargeListResponse, *http.Response, error) {

	cfg := a.client.Cfg
	var (
		localVarPath         = cfg.GetBasePath() + "/dist-api/rechargeList"
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     map[string]string
		localVarFormParams   = url.Values{}
		localVarHeaderParams = make(map[string]string)
		localVarQueryParams  = url.Values{}
		localVarReturnValue  *RechargeListResponse
	)

	r.ctx = a.client.prepareCtx(r.ctx)

	if ok, GenericOpenAPIError := hasReqParam(r.siteId, "SiteId"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}
	localVarQueryParams.Add("siteid", toString(r.siteId))

	if r.startTime != nil {
		localVarQueryParams.Add("starttime", toString(r.startTime))
	}

	if r.endTime != nil {
		localVarQueryParams.Add("endtime", toString(r.endTime))
	}

	if r.page != nil {
		localVarQueryParams.Add("page", toString(r.page))
	}
	if r.pageSize != nil {
		localVarQueryParams.Add("pageSize", toString(r.pageSize))
	}

	if r.payStatus != nil {
		localVarQueryParams.Add("paystatus", toString(r.payStatus))
	}

	req, err := a.client.buildRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.call(r.ctx, req, &localVarReturnValue)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}
	return localVarReturnValue, localVarHTTPResponse, nil
}
